package cn.jeeweb.web.modules.equipment.service.impl;

import cn.jeeweb.common.mybatis.mvc.service.impl.CommonServiceImpl;
import cn.jeeweb.common.mybatis.mvc.wrapper.EntityWrapper;
import cn.jeeweb.common.query.data.Condition;
import cn.jeeweb.common.query.data.Page;
import cn.jeeweb.common.query.data.Queryable;
import cn.jeeweb.web.modules.equipment.entity.EqsOperateApply;
import cn.jeeweb.web.modules.equipment.mapper.EqsOperateApplyMapper;
import cn.jeeweb.web.modules.equipment.service.IEqsOperateApplyService;
import cn.jeeweb.web.modules.sys.Constants;
import cn.jeeweb.web.modules.sys.entity.User;
import cn.jeeweb.web.modules.sys.entity.UserRole;
import cn.jeeweb.web.modules.sys.service.IUserRoleService;
import cn.jeeweb.web.utils.UserUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


/**
* @description: eqs_operate_apply服务接口
*/
@Transactional
@Service("eqsOperateApplyService")
public class EqsOperateApplyServiceImpl extends CommonServiceImpl<EqsOperateApplyMapper,EqsOperateApply> implements IEqsOperateApplyService {

    @Autowired
    private IUserRoleService userRoleService;

    public Page<EqsOperateApply> list(Queryable queryable){
        String roleId = "";
        User currentUser = UserUtils.getUser();
        EntityWrapper<UserRole> entityWrapper = new EntityWrapper<>(UserRole.class);
        entityWrapper.eq("userId",currentUser.getId());
        List<UserRole> userRoleList = userRoleService.selectList(entityWrapper);
        if(userRoleList != null && userRoleList.size() > 0){
            roleId = userRoleList.get(0).getRoleId();
        }
        Condition condition = new Condition();
        if(Constants.OPERATE_ROLE.equals(roleId)){//如果是操作员只能看到自己的申请
            condition.and(Condition.Operator.eq,"createBy",currentUser.getId());
            queryable.setCondition(condition);
        }
        return super.list(queryable);
    }
}